# pip install langchain-mcp-adapters
from major.models_manager import chat_model
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent


client = MultiServerMCPClient(
    {
        "demo": {
            "command": "python",
            "args": [r"D:\workspace\pythonworkspace\chuanzhi\llm_study\major\12_mcp\02_传输模式\01_stdio_sever.py"],
            "transport": "stdio",
        },
    }
)


async def stream_response():
    tools = await client.get_tools()

    agent = create_react_agent(
        chat_model.get_model(),
        tools
    )
    response = await agent.ainvoke(
        {"messages": [{"role": "user", "content": "现在几点"}]}
    )
    print(response["messages"][-1].content)

if __name__ == "__main__":
    import asyncio
    asyncio.run(stream_response())